<!DOCTYPE html>
<html>
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="gray-bg">
<div class="wrapper wrapper-content ">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-content">
                    <input id="pageType" th:value="${pageType}"  type="hidden">
                    <form class="form-horizontal m-t" id="signupForm">
                        <input id="id" name="id" th:value="${sysDict.id}"
                               class="form-control" type="hidden">
                        <div class="form-group">
                            <label class="col-sm-4 control-label"><em class="text-danger">*&nbsp;</em>类型：</label>
                            <div class="col-sm-5">
                                <input id="type" name="type" th:value="${sysDict.type}"
                                       class="form-control" type="text">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-4 control-label"><em class="text-danger">*&nbsp;</em>描述：</label>
                            <div class="col-sm-5">
                                <input id="description" name="description"
                                       th:value="${sysDict.description}" class="form-control"
                                       type="text">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-4 control-label"><em class="text-danger">*&nbsp;</em>标签名：</label>
                            <div class="col-sm-5">
                                <input id="name" name="name" th:value="${sysDict.name}"
                                       class="form-control" type="text">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-4 control-label"><em class="text-danger">*&nbsp;</em>数据值：</label>
                            <div class="col-sm-5">
                                <input id="value" name="value" th:value="${sysDict.value}"
                                       class="form-control" type="text">
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-4 control-label">排序：</label>
                            <div class="col-sm-5">
                                <input id="sort" name="sort" th:value="${sysDict.sort}"
                                       class="form-control" type="text">
                            </div>
                        </div>
                        <div class="form-group hidden">
                            <label class="col-sm-4 control-label ">父级编号：</label>
                            <div class="col-sm-5">
                                <input id="parentId" name="parentId"
                                       th:value="${sysDict.parentId}" class="form-control"
                                       type="text">
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-4 control-label">备注信息：</label>
                            <div class="col-sm-5">
                                <textarea id="remarks" name="remarks" class="form-control" rows="3" th:text="${sysDict.remarks}" ></textarea>

                            </div>
                        </div>
                        <div class="form-group hidden">
                            <label class="col-sm-4 control-label">删除标记：</label>
                            <div class="col-sm-5">
                                <input id="delFlag" name="delFlag"
                                       th:value="${sysDict.delFlag}" class="form-control" type="text">
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="col-sm-5 col-sm-offset-5">
                                <button type="submit" class="btn btn-primary">提交</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
<div th:include="include::footer"></div>
<script type="text/javascript">
    $().ready(function() {
        var pageType = $('#pageType').val();
        if('save'==pageType){//新增页面
            validateRule();

        }else if('update'==pageType){//修改页面
            validateRule();

        }else{
            parent.layer.msg("页面参数错误");
        }

    });

    $.validator.setDefaults({
        submitHandler : function() {
            save();
        }
    });

    function save() {
        $.ajax({
            cache : true,
            type : "POST",
            url : "/common/sysDict/"+$('#pageType').val(),
            data : $('#signupForm').serialize(),// 你的formid
            async : false,
            error : function(request) {
                parent.layer.alert("Connection error");
            },
            success : function(data) {
                if (data.code == 0) {
                    parent.layer.msg("操作成功");
                    $(window.parent.document).find('.J_iframe').each(function () {
                        if ($(this).data('id') == "/common/sysDict") {//common/sysDict为打开的frame id
                            this.contentWindow.reLoad();
                            return false;
                        }
                    });
                    var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
                    parent.layer.close(index);
                } else {
                    parent.layer.alert(data.msg)
                }

            }
        });

    }
    function validateRule() {
        var icon = "<i class='fa fa-times-circle'></i> ";
        $("#signupForm").validate({
            rules : {
                type:{
                    required : true
                },
                description :{
                    required : true
                },
                name : {
                    required : true
                },
                value:{
                    required : true
                }
                ,sort:{
                    range:[0,1000]
                }

            },
            messages : {
                type : {
                    required : icon + "请输入类型"
                },description : {
                    required : icon + "请输入描述"
                },name : {
                    required : icon + "请输入标签名"
                },value : {
                    required : icon + "请输入数据值"
                },sort:{
                    range:icon + "排序数值0-1000"
                }
            }
        })
    }
</script>
</body>
</html>
